package com.inventive.jmscache.server;

import com.inventive.jmscache.server.hazelcast.DataSerializationHelper;

import javax.jms.TextMessage;
import javax.jms.JMSException;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.io.Serializable;

/**
 * @author Grant Little <grant.little@coreservices.com.au>
 */
public class JmsCacheTextMessage extends JmsCacheMessage implements TextMessage, Serializable {

    private String text;

    public JmsCacheTextMessage() {
    }

    public JmsCacheTextMessage(String text) {
        this.text = text;
    }

    public void setText(String text) throws JMSException {
        this.text = text;
    }

    public String getText() throws JMSException {
        return text;
    }

    @Override
    public void writeData(DataOutput dataOutput) throws IOException {
        super.writeData(dataOutput);
        DataSerializationHelper.writeSafeUTF(dataOutput, text);
    }

    @Override
    public void readData(DataInput dataInput) throws IOException {
        super.readData(dataInput);
        text = DataSerializationHelper.readSafeUTF(dataInput);
    }
}
